import Vue from "vue"
import Vuex from "vuex"

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        // 左侧菜单是否折叠  默认展开
        isCollapse: false,
        breadcrumb: [{
            name: "",
            path: ""
        }],
        tags: [{
            name: "home",
            path: "/home",
            title: "首页"
        }]
    },
    getters: {

    },
    mutations: {
        // 更新折叠
        updateCollapse(state, value) {
            if ('' == value) {
                state.isCollapse = !state.isCollapse
            } else {
                state.isCollapse = value
            }
        },
        addTag(state, obj) {
            if (state.tags.some(item => item.path == obj.path))
                return;
            state.tags.push({
                name: obj.name,
                path: obj.path,
                title: obj.title
            })
        },
        delTag(state, obj) {
            for (let [i, p] of state.tags.entries()) {
                if (p.path == obj.path) {
                    state.tags.splice(i, 1);
                    break
                }
            }
        }
    },
    actions: {

    }
})

